#include "head_s.h"


// 和客户端进行通信的函数
int do_worker(int net_fd){
    user_t status;
    
    portocol_t portocol;

    for (;;)
    {
        //char base_path[100] = "\0";             
        //getparameter("base_path", base_path);
        //printf("base_path is = %s", base_path);

        fflush(stdout);
        memset(&status, 0, sizeof(status));
        sprintf(status.base_path, "/home/pockyin/");
        memset(&portocol, 0, sizeof(portocol));
        int ret = 0;
        //printf("worker: user_name = %s, path = %s, mima = %s\n", status.user_name, status.path, status.arg);
        ret = read_stdin(&status, &portocol, net_fd);
        printf("worker: user_name = %s, path = %s, mima = %s\n", status.user_name, status.path, status.arg);
        printf("cmd: %d\n", portocol.cmd);
        printf("ret = %d\n", ret);
        if (ret == 0)
        {
            break;
        }
        //printf("cmd: %d\n", portocol.cmd);
        switch(portocol.cmd)
        {
        case CD:
            cd(&status, &portocol, net_fd);
            break;
        case LS:
            ls(&status, &portocol, net_fd);
            break;
       /* case PUTS:
            upload(&status, &portocol, net_fd);
            break;*/
        case GETS:
            download(&status, &portocol, net_fd);
            break;
        case RM:
            rm(&status, &portocol, net_fd);
            break;
        case PWD:
            pwd(&status, &portocol, net_fd);
            break;
        case MKDIR:
            create_dir(&status, &portocol, net_fd);
            break;
        case LOGIN:
            //printf("1111111\n");
            login(&status, &portocol, net_fd);
            break;
        case REGISTER:
            regist(&status, &portocol, net_fd);
            break;
        }
    }


    return  0;
}


